/**
 * Description: RegisterInfoAction.java
 * Copyright (c) 2008-2009  Neo. 
 * All Rights Reserved.
 * @version 1.0  Mar 30, 2009 10:11:25 PM 李萌（neolimeng@gmail.com）created
 */
package org.paradise.dms.web.action.registerinfo;

import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.apache.struts2.ServletActionContext;
import org.directwebremoting.annotations.RemoteProxy;
import org.paradise.dms.pojo.RegisterInfo;
import org.paradise.dms.services.RegisterInfoService;
import org.paradise.dms.web.action.DMSBaseAction;
import org.paradise.dms.web.tools.Pager;
import org.paradise.dms.web.tools.PagerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

/**
 * Description: Copyright (c) 2008-2009 Neo. All Rights Reserved.
 * 
 * @version 1.0 Mar 30, 2009 10:11:25 PM 李萌（neolimeng@gmail.com）created
 */
@RemoteProxy(name = "registerInfoAction")
@Service
public class RegisterInfoAction extends DMSBaseAction {
	/**
	 * 
	 */
	private static final long serialVersionUID = -1033144997446567562L;

	private static Logger log = Logger.getLogger(RegisterInfoAction.class);

	@Autowired
	@Qualifier("registerInfoServiceImpl")
	private RegisterInfoService registerInfoService;

	private RegisterInfo ri;
	private List<RegisterInfo> rl;
	
	@Autowired
	private PagerService pagerService;
	private Pager pager;
	protected String currentPage;
	protected String totalRows;
	protected String pagerMethod;

	public String listAllRegisterInfo() {
		try {
			HttpSession session = ServletActionContext.getRequest().getSession();
			String recorderId=(String) session.getAttribute("systemuserid");
			log.info("DMS_info_用户操作，操作者ID为"+recorderId);
			int totalRow = this.registerInfoService.getRows();
			pager = pagerService.getPager(this.getCurrentPage(), this
					.getPagerMethod(), totalRow);
			this.setCurrentPage(String.valueOf(pager.getCurrentPage()));
			this.setTotalRows(String.valueOf(totalRow));
			rl = this.registerInfoService.listAllRegisterInfo(pager
					.getPageSize(), pager.getStartRow());
			return SUCCESS;
		} catch (Exception e) {
			e.printStackTrace();
			return INPUT;
		}
	}

	/**
	 * 
	 * Description: Action-插入一条物品登记记录
	 * 
	 * @Version1.0 Mar 30, 2009 10:19:09 PM 李萌（neolimeng@gmail.com）创建
	 * @return
	 */
	public String insertRegisterInfo() {
		HttpSession session = ServletActionContext.getRequest().getSession();
		String recorderId=(String) session.getAttribute("systemuserid");
		String recorderName=(String)session.getAttribute("systemusername");
		log.info("DMS_info_用户操作，操作者ID为"+recorderId);
		ri.setRegisterinfoind(1);
		ri.setRegisterinforecordedby(recorderName);
		ri.setRegisterinfotime(new Date());
		if (this.registerInfoService.insertRegisterInfo(ri)) {
			return SUCCESS;
		} else
			return INPUT;
	}

	/**
	 * 
	 * Description: Action-更新一条物品登记记录
	 * 
	 * @Version1.0 Mar 30, 2009 10:19:09 PM 李萌（neolimeng@gmail.com）创建
	 * @return
	 */
	public String updateRegisterInfo() {
		HttpSession session = ServletActionContext.getRequest().getSession();
		String recorderId=(String) session.getAttribute("systemuserid");
		log.info("DMS_info_用户操作，操作者ID为"+recorderId);
		if (this.registerInfoService.updateRegisterInfo(ri)) {
			return SUCCESS;
		} else
			return INPUT;
	}

	/**
	 * 
	 * Description: Action-删除一条物品登记记录
	 * 
	 * @Version1.0 Mar 30, 2009 10:19:09 PM 李萌（neolimeng@gmail.com）创建
	 * @return
	 */
	public String deleteRegisterInfo() {
		HttpSession session = ServletActionContext.getRequest().getSession();
		String recorderId=(String) session.getAttribute("systemuserid");
		log.info("DMS_info_用户操作，操作者ID为"+recorderId);
		int registerinfoid = Integer.parseInt(ServletActionContext.getRequest()
				.getParameter("registerinfoid"));
		if (this.registerInfoService.deleteRegisterInfo(registerinfoid)) {
			return SUCCESS;
		} else
			return INPUT;
	}

	/**
	 * 
	 * Description: Action-取得一条物品登记记录
	 * 
	 * @Version1.0 Mar 30, 2009 10:19:09 PM 李萌（neolimeng@gmail.com）创建
	 * @return
	 */
	public String getRegisterInfo() {
		try {
			HttpSession session = ServletActionContext.getRequest().getSession();
			String recorderId=(String) session.getAttribute("systemuserid");
			log.info("DMS_info_用户操作，操作者ID为"+recorderId);
			int registerinfoid = Integer.parseInt(ServletActionContext
					.getRequest().getParameter("registerinfoid"));
			ri = this.registerInfoService.getRegisterInfo(registerinfoid);
			return SUCCESS;
		} catch (Exception e) {
			e.printStackTrace();
			return INPUT;
		}
	}

	/**
	 * 
	 * Description: Action-取得所有物品登记记录
	 * 
	 * @Version1.0 Mar 30, 2009 10:19:09 PM 李萌（neolimeng@gmail.com）创建
	 * @return
	 */
	public String getAllRegisterInfo() {
		try {
			HttpSession session = ServletActionContext.getRequest().getSession();
			String recorderId=(String) session.getAttribute("systemuserid");
			log.info("DMS_info_用户操作，操作者ID为"+recorderId);
			rl = this.registerInfoService.getAllRegisterInfo();
			log.info("查到多少条物品登记记录？" + rl.size());
			return SUCCESS;
		} catch (Exception e) {
			e.printStackTrace();
			return INPUT;
		}
	}

	public String setReturnByID() {
		try {
			HttpSession session = ServletActionContext.getRequest().getSession();
			String recorderId=(String) session.getAttribute("systemuserid");
			log.info("DMS_info_用户操作，操作者ID为"+recorderId);
			int registerinfoid = Integer.parseInt(ServletActionContext
					.getRequest().getParameter("registerinfoid"));
			this.registerInfoService.setReturnTime(registerinfoid);
			return SUCCESS;
		} catch (Exception e) {
			e.printStackTrace();
			return INPUT;
		}
	}

	/**
	 * @return the registerInfoService
	 */
	public RegisterInfoService getRegisterInfoService() {
		return registerInfoService;
	}

	/**
	 * @param registerInfoService
	 *            the registerInfoService to set
	 */
	public void setRegisterInfoService(RegisterInfoService registerInfoService) {
		this.registerInfoService = registerInfoService;
	}

	/**
	 * @return the ri
	 */
	public RegisterInfo getRi() {
		return ri;
	}

	/**
	 * @param ri
	 *            the ri to set
	 */
	public void setRi(RegisterInfo ri) {
		this.ri = ri;
	}

	/**
	 * @return the rl
	 */
	public List<RegisterInfo> getRl() {
		return rl;
	}

	/**
	 * @param rl
	 *            the rl to set
	 */
	public void setRl(List<RegisterInfo> rl) {
		this.rl = rl;
	}

	public PagerService getPagerService() {
		return pagerService;
	}

	public void setPagerService(PagerService pagerService) {
		this.pagerService = pagerService;
	}

	public Pager getPager() {
		return pager;
	}

	public void setPager(Pager pager) {
		this.pager = pager;
	}

	public String getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(String currentPage) {
		this.currentPage = currentPage;
	}

	public String getTotalRows() {
		return totalRows;
	}

	public void setTotalRows(String totalRows) {
		this.totalRows = totalRows;
	}

	public String getPagerMethod() {
		return pagerMethod;
	}

	public void setPagerMethod(String pagerMethod) {
		this.pagerMethod = pagerMethod;
	}
}
